package sg.edu.nus.iss.billing.controller;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;

import sg.edu.nus.iss.billing.model.charge.Rate;
import sg.edu.nus.iss.billing.utils.PropertiesRead;

/**
 * @author ZiFeng, Thurien, YiNi
 *
 */
public class RateController  {
	private static final long serialVersionUID = 1L;

	private static RateController rateProps;

	private PropertiesRead propertiesRead;

	private Calendar calender;

	private RateController() {
		calender = Calendar.getInstance();
		calender.set(2011, 1, 1);

		propertiesRead = new PropertiesRead();
		FileInputStream fis;
		try {
			fis = new FileInputStream("properties/serviceRate.properties");
			propertiesRead.load(fis);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static synchronized RateController getInstance() {
		if (rateProps == null) {
			rateProps = new RateController();
		}
		return rateProps;
	}

	public Rate getRate(String rateType) {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty(rateType)), calender.getTime());
		rate.setRateType(rateType);
		return rate;
	}

	
}
